﻿using System.Configuration;
using System.Data;
using System.Windows;

using System.Windows.Threading;
using Parylene_CVD.Stores;
using Parylene_CVD.ViewModel;
using Parylene_CVD.Service;

namespace Parylene_CVD
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        private readonly NavigationStore _navigationStore;
        public App()
        {
            _navigationStore = new NavigationStore();
        }
        protected override void OnStartup(StartupEventArgs e)
        {
            //_navigationStore.CurrentViewModel = CreateHomeViewModel();
            _navigationStore.CurrentViewModel = CreateLoginViewModel();
            MainWindow = new MainWindow()
            {
                DataContext = new MainViewModel(_navigationStore)
            };
            MainWindow.Show();
            base.OnStartup(e);
        }


        private LoginViewModel CreateLoginViewModel()
        {
            return new LoginViewModel(new NavigationService(_navigationStore, CreateHomeViewModel));
        }
        private HomeViewModel CreateHomeViewModel()
        {
            return new HomeViewModel(new NavigationService(_navigationStore, CreateSetViewModel), new NavigationService(_navigationStore, CreateDeviceMonitorViewModel),new NavigationService(_navigationStore, CreateHomeOpenViewModel), new NavigationService(_navigationStore, CreateHomeCloseViewModel));
        }
        private HomeOpenViewModel CreateHomeOpenViewModel()
        {
            return new HomeOpenViewModel(new NavigationService(_navigationStore, CreateSetViewModel), new NavigationService(_navigationStore, CreateDeviceMonitorViewModel), new NavigationService(_navigationStore, CreateHomeViewModel), new NavigationService(_navigationStore, CreateHomeCloseViewModel));
        }
        private HomeCloseViewModel CreateHomeCloseViewModel()
        {
            return new HomeCloseViewModel(new NavigationService(_navigationStore, CreateSetViewModel), new NavigationService(_navigationStore, CreateDeviceMonitorViewModel), new NavigationService(_navigationStore, CreateHomeViewModel), new NavigationService(_navigationStore, CreateHomeOpenViewModel));
        }
        private SetViewModel CreateSetViewModel()
        {
            return new SetViewModel(new NavigationService(_navigationStore, CreateHomeViewModel),
                new NavigationService(_navigationStore, CreateUserManagementViewModel), new NavigationService(_navigationStore, CreateDeviceManagementViewModel));
        }
        private DeviceManagementViewModel CreateDeviceManagementViewModel()
        {
            return new DeviceManagementViewModel(new NavigationService(_navigationStore, CreateHomeViewModel), new NavigationService(_navigationStore, CreateAddDeviceViewModel));
        }
        private UserManagementViewModel CreateUserManagementViewModel()
        {
            return new UserManagementViewModel(new NavigationService(_navigationStore, CreateHomeViewModel), new NavigationService(_navigationStore, CreateAddUserViewModel));
        }
        private AddUserViewModel CreateAddUserViewModel()
        {
            return new AddUserViewModel(new NavigationService(_navigationStore, CreateUserManagementViewModel));
        }
        private AddDeviceViewModel CreateAddDeviceViewModel()
        {
            return new AddDeviceViewModel(new NavigationService(_navigationStore, CreateDeviceManagementViewModel));
        }

        private DeviceMonitorViewModel CreateDeviceMonitorViewModel()
        {
            return new DeviceMonitorViewModel(new NavigationService(_navigationStore, CreateDataCurveViewModel),
                new NavigationService(_navigationStore, CreateDataRecordViewModel), new NavigationService(_navigationStore, CreateAlarmEventViewModel),
                new NavigationService(_navigationStore, CreateHomeViewModel));
        }
        private DataCurveViewModel CreateDataCurveViewModel()
        {
            return new DataCurveViewModel(new NavigationService(_navigationStore, CreateDeviceMonitorViewModel), 
                new NavigationService(_navigationStore, CreateDataRecordViewModel), new NavigationService(_navigationStore, CreateAlarmEventViewModel),
                new NavigationService(_navigationStore, CreateHomeViewModel));
        }
        private DataRecordViewModel CreateDataRecordViewModel()
        {
            return new DataRecordViewModel(new NavigationService(_navigationStore, CreateDeviceMonitorViewModel),
                new NavigationService(_navigationStore, CreateDataCurveViewModel), new NavigationService(_navigationStore, CreateAlarmEventViewModel),
                new NavigationService(_navigationStore, CreateHomeViewModel));
        }
        private AlarmEventViewModel CreateAlarmEventViewModel()
        {
            return new AlarmEventViewModel(new NavigationService(_navigationStore, CreateDeviceMonitorViewModel),
                new NavigationService(_navigationStore, CreateDataCurveViewModel), new NavigationService(_navigationStore, CreateDataRecordViewModel),
                new NavigationService(_navigationStore, CreateHomeViewModel));
        }
    }

}
